import wsgiref.handlers
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp \
	import template
import os, glob


class MainHandler(webapp.RequestHandler):
  def get(self):
	
	filelst = os.listdir('documents')
	filenum = len(filelst)
	user = users.get_current_user()
	if user:
	      greeting = ("Welcome, %s! (<a href=\"%s\">sign out</a>)" %
	                  (user.nickname(), users.create_logout_url("/")))
	else:
	      greeting = ("<a href=\"%s\">Sign in with Google Account</a>" %
	                  users.create_login_url("/"))
	values = {
		'filenum':filenum,
		'filelst':filelst,
		'user':user,
		'greeting':greeting,
	}
	self.response.out.write(template.render('documents.html', values))
### User Signin
	    

def main():
  application = webapp.WSGIApplication([('/documents\.html', MainHandler)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()


